<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>动态实例化demo</title>
  <style>
    body {
      margin: 0;
      overflow: hidden;
    }
    canvas {
      outline: none;
    }
  </style>
</head>
<body>
  <script type="x-shader/x-vertex" id="vertexShader">
    precision highp float;

    attribute vec3 offset;
    attribute vec4 orientation;

    varying vec2 vUv;

    vec3 applyQuaternionToVector( vec4 q, vec3 v ){

			return v + 2.0 * cross( q.xyz, cross( q.xyz, v ) + q.w * v );

		}

    void main() {
      vec3 vPosition = applyQuaternionToVector(orientation, position);

      vUv = uv;

      gl_Position = projectionMatrix * modelViewMatrix * vec4(offset + vPosition, 1.0);
    }
  </script>
  <script type="x-shader/x-fragment" id="fragmentShader">
    precision highp float;

    uniform sampler2D map;

    varying vec2 vUv;

    void main() {
      gl_FragColor = texture2D(map, vUv);
    }
  </script>
  <script src="./_instancing_dynamic.js" type="module"></script>
</body>
</html>